home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / winsr173.zip / SELECT.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  7KB  |  241 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Select.c
  4.  
  5.     PURPOSE: Contains library routines for selecting a region
  6.  
  7.     FUNCTIONS:
  8.  
  9.     StartSelection(HWND, POINT, LPRECT, int) - begin selection area
  10.     UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  11.     EndSelection(POINT, LPRECT) - end selection area
  12.     ClearSelection(HWND, LPRECT, int) - clear selection area
  13.  
  14. *******************************************************************************/
  15.  
  16. #include "windows.h"
  17. #include "select.h"
  18.  
  19. extern BOOL bTrack, bMove, bMoving;
  20.  
  21. /****************************************************************************
  22.  
  23.     FUNCTION: StartSelection(HWND, POINT, LPRECT, int)
  24.  
  25.     PURPOSE: Begin selection of region
  26.  
  27. ****************************************************************************/
  28.  
  29.  
  30. POINT Center, DragPoint, ZoomDim;
  31.  
  32. void FAR PASCAL StartSelection(hWnd, ptCurrent, lpSelectRect, fFlags)
  33. HWND hWnd;
  34. POINT ptCurrent;
  35. LPRECT lpSelectRect;
  36. int fFlags;
  37. {
  38.     if (lpSelectRect->left != lpSelectRect->right ||
  39.         lpSelectRect->top != lpSelectRect->bottom)
  40.     ClearSelection(hWnd, lpSelectRect, fFlags);
  41.  
  42.     lpSelectRect->right = ptCurrent.x;
  43.     lpSelectRect->bottom = ptCurrent.y;
  44.  
  45.     /* If you are extending the box, then invert the current rectangle */
  46.  
  47.     if ((fFlags & SL_SPECIAL) == SL_EXTEND)
  48.     ClearSelection(hWnd, lpSelectRect, fFlags);
  49.  
  50.     /* Otherwise, set origin to current location */
  51.  
  52.     else {
  53.     lpSelectRect->left = ptCurrent.x;
  54.     lpSelectRect->top = ptCurrent.y;
  55.         Center = ptCurrent;
  56.     }
  57.     SetCapture(hWnd);
  58. }
  59.  
  60. extern int xdots, ydots;
  61.  
  62. /****************************************************************************
  63.  
  64.     FUNCTION: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  65.  
  66.     PURPOSE: Update selection
  67.  
  68. ****************************************************************************/
  69.  
  70. void FAR PASCAL UpdateSelection(hWnd, ptCurrent, lpSelectRect, fFlags)
  71. HWND hWnd;
  72. POINT ptCurrent;
  73. LPRECT lpSelectRect;
  74. int fFlags;
  75. {
  76.     HDC hDC;
  77.     short OldROP;
  78.     POINT NewDim, NewPoint;
  79.     unsigned ScaledY;
  80.  
  81.     hDC = GetDC(hWnd);
  82.  
  83.     switch (fFlags & SL_TYPE) {
  84.  
  85.     case SL_BOX:
  86.          OldROP = SetROP2(hDC, R2_NOTXORPEN);
  87.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  88.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  89.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  90.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  91.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  92.  
  93.         LineTo(hDC, ptCurrent.x, lpSelectRect->top);
  94.         LineTo(hDC, ptCurrent.x, ptCurrent.y);
  95.         LineTo(hDC, lpSelectRect->left, ptCurrent.y);
  96.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  97.         SetROP2(hDC, OldROP);
  98.         break;
  99.     
  100.     case SL_BLOCK:
  101.         PatBlt(hDC,
  102.         lpSelectRect->left,
  103.         lpSelectRect->bottom,
  104.         lpSelectRect->right - lpSelectRect->left,
  105.         ptCurrent.y - lpSelectRect->bottom,
  106.         DSTINVERT);
  107.         PatBlt(hDC,
  108.         lpSelectRect->right,
  109.         lpSelectRect->top,
  110.         ptCurrent.x - lpSelectRect->right,
  111.         ptCurrent.y - lpSelectRect->top,
  112.         DSTINVERT);
  113.         break;
  114.  
  115.         /* MCP 6-3-92 */
  116.         case (SL_ZOOM):
  117.        OldROP = SetROP2(hDC, R2_NOTXORPEN);
  118.        MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  119.        LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  120.        LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  121.        LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  122.        LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  123.  
  124.            if(bTrack)
  125.            {
  126.               NewPoint = ptCurrent;
  127.  
  128.               NewDim.x = Center.x - NewPoint.x;
  129.               if(NewDim.x < 0)
  130.                  NewDim.x = -NewDim.x;
  131.  
  132.               NewDim.y = Center.y - NewPoint.y;
  133.               if(NewDim.y < 0)
  134.                  NewDim.y = -NewDim.y;
  135.  
  136.               ScaledY = (unsigned)(((long)NewDim.y) * xdots / ydots);
  137.               if(NewDim.x < ScaledY)
  138.                  NewDim.x = ScaledY;
  139.               else
  140.                  NewDim.y = (unsigned)(((long)NewDim.x) * ydots / xdots);
  141.  
  142.               if(NewDim.x < 2)
  143.                  NewDim.x = 2;
  144.               if(NewDim.y < 2)
  145.                  NewDim.y = 2;
  146.  
  147.               ZoomDim = NewDim;
  148.            }
  149.            else if(bMoving)
  150.            {
  151.               Center.x += ptCurrent.x - DragPoint.x;
  152.               Center.y += ptCurrent.y - DragPoint.y;
  153.               DragPoint = ptCurrent;
  154.            }
  155.  
  156.            if (bTrack || bMoving) {
  157.               lpSelectRect->left   = Center.x - ZoomDim.x;
  158.               lpSelectRect->right  = Center.x + ZoomDim.x;
  159.               lpSelectRect->bottom = Center.y + ZoomDim.y;
  160.               lpSelectRect->top    = Center.y - ZoomDim.y;
  161.  
  162.                MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  163.           LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  164.           LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  165.           LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  166.           LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  167.           }
  168.  
  169.        SetROP2(hDC, OldROP);
  170.            ReleaseDC(hWnd, hDC);
  171.            return;
  172.     }
  173.     lpSelectRect->right = ptCurrent.x;
  174.     lpSelectRect->bottom = ptCurrent.y;
  175.     ReleaseDC(hWnd, hDC);
  176. }
  177.  
  178. /****************************************************************************
  179.  
  180.     FUNCTION: EndSelection(POINT, LPRECT)
  181.  
  182.     PURPOSE: End selection of region, release capture of mouse movement
  183.  
  184. ****************************************************************************/
  185.  
  186. void FAR PASCAL EndSelection(ptCurrent, lpSelectRect)
  187. POINT ptCurrent;
  188. LPRECT lpSelectRect;
  189. {
  190.     if(!bMove)
  191.     {
  192.        lpSelectRect->right = ptCurrent.x;
  193.        lpSelectRect->bottom = ptCurrent.y;
  194.     }
  195.     ReleaseCapture();
  196. }
  197.  
  198. /****************************************************************************
  199.  
  200.     FUNCTION: ClearSelection(HWND, LPRECT, int) - clear selection area
  201.  
  202.     PURPOSE: Clear the current selection
  203.  
  204. ****************************************************************************/
  205.  
  206. void FAR PASCAL ClearSelection(hWnd, lpSelectRect, fFlags)
  207. HWND hWnd;
  208. LPRECT lpSelectRect;
  209. int fFlags;
  210. {
  211.     HDC hDC;
  212.     short OldROP;
  213.  
  214.     hDC = GetDC(hWnd);
  215.     switch (fFlags & SL_TYPE) {
  216.  
  217.         /* MCP 6-3-92 */
  218.         case (SL_ZOOM):
  219.     case SL_BOX:
  220.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  221.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  222.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  223.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  224.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  225.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  226.         SetROP2(hDC, OldROP);
  227.         break;
  228.  
  229.     case SL_BLOCK:
  230.         PatBlt(hDC,
  231.         lpSelectRect->left,
  232.         lpSelectRect->top,
  233.         lpSelectRect->right - lpSelectRect->left,
  234.         lpSelectRect->bottom - lpSelectRect->top,
  235.         DSTINVERT);
  236.         break;
  237.  
  238.     }
  239.     ReleaseDC(hWnd, hDC);
  240. }
  241.